#!/usr/bin/python

#The goal of this script is to find the dependencies between all the initcalls.

import commonLib
import findDependenciesLib
import os, sys
import pickle
#We check if there is a restore file
pwd = os.getcwd()
if os.path.exists(pwd+'/restore'+sys.argv[1]):
	NodeCollection = findDependenciesLib.restore(sys.argv[1])
else:
	mySerialPortInterface = commonLib.serialPortInterface(int(commonLib.getOptions()['serial']))
	commonLib.createSymbolicLinkToKernelImage()
	numberOfInitCalls = findDependenciesLib.getNumberOfInitCalls(mySerialPortInterface)
	NodeCollection = findDependenciesLib.findDependencies(numberOfInitCalls,mySerialPortInterface)
	findDependenciesLib.findLastDependencies(NodeCollection,mySerialPortInterface)


#Now that we're done we can save the precious NodeCollection in a file
#so that the others scripts can use it

f = open('NodeCollection','w')
f.write(pickle.dumps(NodeCollection))
f.close()

